package gui;

import objects.Departement;
import objects.Pays;
import objects.Quartier;
import objects.Region;
import objects.Ville;

public class ComboWithId {
	
	private String[] values;
	private int[] ids;
	
	public ComboWithId(Pays[] list){
		this.setNewData(list);
	}
	
	public ComboWithId(Region[] list){
		this.setNewData(list);
	}
	
	public ComboWithId(Departement[] list){
		this.setNewData(list);
	}
	
	public ComboWithId(Ville[] list){
		this.setNewData(list);
	}
	
	public ComboWithId(Quartier[] list){
		this.setNewData(list);
	}
	
	public void setNewData(Pays[] list){
		this.values=new String[list.length+1];
		this.ids=new int[list.length+1];
		this.values[0]="choisissez un pays";
		this.ids[0]=-1;
		for(int i=0; i<list.length; i++)
		{
			this.values[i+1]=list[i].getNom();
			this.ids[i+1]=list[i].getId_pays();
		}
	}
	
	public void setNewData(Region[] list){
		this.values=new String[list.length+1];
		this.ids=new int[list.length+1];
		this.values[0]="choisissez une region";
		this.ids[0]=-1;
		for(int i=0; i<list.length; i++)
		{
			this.values[i+1]=list[i].getNom();
			this.ids[i+1]=list[i].getId_region();
		}
	}
	
	public void setNewData(Departement[] list){
		this.values=new String[list.length+1];
		this.ids=new int[list.length+1];
		this.values[0]="choisissez un département";
		this.ids[0]=-1;
		for(int i=0; i<list.length; i++)
		{
			this.values[i+1]=list[i].getNom();
			this.ids[i+1]=list[i].getId_departement();
		}
	}
	
	public void setNewData(Ville[] list){
		this.values=new String[list.length+1];
		this.ids=new int[list.length+1];
		this.values[0]="choisissez une ville";
		this.ids[0]=-1;
		for(int i=0; i<list.length; i++)
		{
			this.values[i+1]=list[i].getNom();
			this.ids[i+1]=list[i].getId_ville();
		}
	}
	
	public void setNewData(Quartier[] list){
		this.values=new String[list.length+1];
		this.ids=new int[list.length+1];
		this.values[0]="choisissez un quartier";
		this.ids[0]=-1;
		for(int i=0; i<list.length; i++)
		{
			this.values[i+1]=list[i].getNom();
			this.ids[i+1]=list[i].getId_quartier();
		}
	}
	
	public String[] getValues()
	{
		return values;
	}
	
	public int[] getIDs()
	{
		return ids;
	}
	
	public int indexOf(int id)
	{
		for(int i=0; i<this.ids.length; i++)
			if(ids[i]==id)
				return i;
		System.out.println("erreur index");
		return 0;
	}
}
